<?php
#DP 31-04-2012
# Testowanie generowania pdfow przez zenda 
# bende wykorzystywal klase wbuodwana w zenda

class TestPdfController extends Zend_Controller_Action
{

    public function init()
    {
      
    }

    public function indexAction()
    {
       echo 'PDF konktoler - akcja inex. <br>zend ';  
    }

   #1. tworenie pdfu i z apisanie go na dysku tam gdzie jest index.php
 	public function testAction()
    {
		try 
		{
		  $pdf = new Zend_Pdf();
		  // create A4 page
		  $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
		  // define font resource

		  // set font for page
		
		  $font = Zend_Pdf_Font::fontWithPath('c:\arial.ttf');
			$page->setFont($font, 14);
			$page->drawText('That whichłąśśććŹŹŻŻ**** we call a rose,', 70, 720, 'UTF-8');

		  $pdf->pages[] = $page;
		  // save as file
		  $pdf->save('example.pdf');
		  
		  echo 'Powodzenie poprawnie utworzono i zapisano na dysku w plik pdf';
		  $this->render('index');
		} 
		catch (Zend_Pdf_Exception $e) 
		{
		  die ('PDF error: ' . $e->getMessage());
		}
		catch (Exception $e)
		{
		  die ('Application error: ' . $e->getMessage());
		} 
	}

	public function test2Action()
	{
	try 
		{
		  $pdf = new Zend_Pdf();
		  // create A4 page
		  $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
		  // define font resource

		  // set font for page
		
		  $font = Zend_Pdf_Font::fontWithPath('c:\arial.ttf');
			$page->setFont($font, 14);
			$page->drawText('That whichłąśśććŹŹŻŻ**** we call a rose,', 70, 720, 'UTF-8');

		  $pdf->pages[] = $page;
		  // save as file
		  $pdf->save('example2.pdf');
		  header('Content-type: application/pdf');
		header('Content-Disposition: attachment; filename="example2.pdf"');
		  echo $pdf->render();
		 
		  $this->render('index');
		} 
		catch (Zend_Pdf_Exception $e) 
		{
		  die ('PDF error: ' . $e->getMessage());
		}
		catch (Exception $e)
		{
		  die ('Application error: ' . $e->getMessage());
		} 	
	
	}
	
	
	public function test3Action()
	{
	// include auto-loader class
// register auto-loader
$loader = Zend_Loader_Autoloader::getInstance();

try {
  // create PDF
  $pdf = new Zend_Pdf();

  // create A4 page
  $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);

  // define a style
  $cerulean = new Zend_Pdf_Style();
  $cerulean->setFillColor(new Zend_Pdf_Color_Rgb(0, 161, 224));
  $cerulean->setLineColor(new Zend_Pdf_Color_Rgb(0, 161, 224));
  $cerulean->setLineWidth(5);
  $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
  $cerulean->setFont($font, 32);  

  // define another style
  $crimson = new Zend_Pdf_Style();
  $crimson->setFillColor(new Zend_Pdf_Color_Rgb(194, 0, 0));
  $crimson->setLineColor(new Zend_Pdf_Color_Rgb(194, 0, 0));
  $crimson->setLineWidth(2);
  $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES_ROMAN);
  $crimson->setFont($font, 20);  

  // write text to page
  // using different styles
  $page->setStyle($cerulean)
       ->drawText('That which we call a rose,', 72, 720);

  $page->setStyle($crimson)
       ->drawText('By any other name would smell as sweet.', 72, 620);

  // add page to document
  $pdf->pages[] = $page;

  //$pdf->save('example3.pdf');
  // send to browser as download
  //header("Content-Disposition: inline; filename=example.pdf");
  //header('Content-Type: application/x-pdf');
  
  /*
  $this->getResponse()
             ->setHeader('Content-Disposition:attachment', ';filename=result.pdf')
                        ->setHeader('Content-Type', 'application/x-pdf');
  fpassthru('result.pdf');
*/
header("Content-Type: application/x-pdf");
header("Content-Disposition: attachment; filename=invoice-". date("Y-m-d-H-i") . ".pdf");
header("Cache-Control: no-cache, must-revalidate");
  
  
  echo $pdf->render();
  //$this->render('index');
  
} 
catch (Zend_Pdf_Exception $e) {
  die ('PDF error: ' . $e->getMessage());
}
 catch (Exception $e) {
  die ('Application error: ' . $e->getMessage());
}
	
}
	
}

